home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.07 Jul 93 / Embedded Software / EKGmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-09  |  3.3 KB  |  173 lines  |  [TEXT/MPS ]

  1. /* filename: EKGmain.c
  2.  *
  3.  * This is tha main file for the system.
  4.  */
  5.  
  6. /* Assembly routine that presets the A5 register to a place in
  7.  * RAM that we know to be a good spot for global data.  As it
  8.  * turns out, the A5 location is set below A7 (the stack pointer)
  9.  * in our embedded system RAM
  10.  */
  11. extern void InitA5Reg(void);
  12.  
  13. typedef enum {
  14.     ACQ_INHIBITED  = 1,
  15.     ACQ_ABORT      = 2,
  16.     OK             = 3,
  17.     ACQ_INCOMPLETE = 4,
  18. } STATUS;
  19.  
  20. /* This typedef would need to be reversed for little-endian target machines 
  21.  */ 
  22. typedef struct {
  23.     unsigned AcqHoldoff   : 1 ;  /* Read/Write bit 0    */
  24.     unsigned AcqComplete  : 1 ;  /* Read ONLY  bit 1    */
  25.     unsigned AcqInProcess : 1 ;  /* Read ONLY  bit 2    */
  26.     unsigned AcqStart     : 1 ;  /* Write ONLY bit 3    */
  27.     unsigned AcqAbort     : 1 ;  /* Write ONLY bit 4    */
  28.     unsigned unused       : 3 ;  /* unused     bits 5-7 */
  29. } tAcqStatus;
  30.  
  31. typedef unsigned char uint8;
  32. typedef unsigned char boolean;
  33.  
  34. #ifdef _NOT_SIMULATING_
  35.  
  36. #define ACQ_STATUS_REG_ADDR ( 0x00300000 ) 
  37.  
  38. #endif
  39.  
  40. tAcqStatus *AcqStatusReg;
  41.  
  42. boolean TheCowsAreOutRoaming;
  43.  
  44. /* Function protos
  45.  */
  46. void InitGlobals();
  47. STATUS DoAnalysis();
  48. STATUS DoDisplay();
  49. STATUS DoAcquisition();
  50.  
  51.  
  52. /************************************************* main() *
  53.  *
  54.  *
  55.  */
  56.  
  57. void main()
  58. {
  59.    STATUS Status;
  60.    
  61.    InitGlobals();
  62.    
  63.    /* Run power-on self tests here
  64.     */
  65.    
  66.    /* attempt an acquisition, then analyze and display
  67.     * if successful
  68.     */
  69.    while ( TheCowsAreOutRoaming ) {
  70.    
  71.       if ( (Status = DoAcquisition() ) == OK ) {
  72.          (void) DoAnalysis();
  73.          (void) DoDisplay();
  74.       }
  75.       else {
  76.          while (1) {
  77.              ;  /* universal error trap ! */
  78.             }
  79.       }
  80.       
  81.    }
  82. }
  83.  
  84. /****************************************** InitGlobals() *
  85.  *
  86.  * This routine sets up the globals (call it immediately).
  87.  */
  88.  
  89. void InitGlobals() {
  90.  
  91. #ifdef _NOT_SIMULATING_
  92.  
  93.     InitA5Reg();  /* preset the global data register to RAM */
  94.     
  95.    /* set pointer to the hardware
  96.     */
  97.    AcqStatusReg =  (tAcqStatus *) ACQ_STATUS_REG_ADDR;
  98. #endif
  99.  
  100.    /* init acq hardware 
  101.     */
  102.    AcqStatusReg->AcqAbort     = 1;
  103.    AcqStatusReg->AcqHoldoff   = 0;
  104.    AcqStatusReg->AcqStart     = 0;
  105.    
  106.    TheCowsAreOutRoaming = 1;
  107. }
  108.  
  109. /******************************************* DoAnalysis() *
  110.  *
  111.  * This routine would extract measurement results from the
  112.  * raw acquired data.
  113.  */
  114.  
  115. STATUS DoAnalysis() {
  116.  
  117.    static STATUS PriorAcq;
  118.    
  119.    PriorAcq = OK;
  120.    return (OK);
  121. }
  122.  
  123. /******************************************** DoDisplay() *
  124.  *
  125.  * This routine would display the data acquired.
  126.  */
  127.  
  128. STATUS DoDisplay() {
  129.    return (OK);
  130. }
  131.  
  132. /**************************************** DoAcquisition() *
  133.  *
  134.  * This routine manages the acquisition of data.
  135.  */
  136.  
  137. STATUS DoAcquisition() {
  138.  
  139. #ifdef _NOT_SIMULATING_
  140.  
  141.    /* if acquisitions are inhibited, then forget it
  142.     */
  143.    if ( !AcqStatusReg->AcqHoldoff ) {
  144.     
  145.       /* start an acquisition
  146.        */
  147.       AcqStatusReg->AcqStart = 1;
  148.        
  149.       while ( AcqStatusReg->AcqInProcess ) { 
  150.            ; /* wait for the acq to finish */
  151.       }
  152.       
  153.       /* check to see if acq was completed
  154.        */
  155.       if ( AcqStatusReg->AcqComplete ) {
  156.          return (OK);
  157.       }
  158.       else {
  159.          return (ACQ_INCOMPLETE);
  160.       }
  161.       
  162.    }
  163.    else {  /* acqs are inhibited */
  164.       return (ACQ_INHIBITED);
  165.    }
  166.   
  167. #else  
  168.  
  169. /* simulation routines would go in here */
  170.  
  171. #endif /* _NOT_SIMULATING_ */
  172. }
  173.